#include "widget.h"
#include "ui_widget.h"

#include <QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QShortcut *cut1 = new QShortcut(this);
    cut1->setKey(QKeySequence("-"));
    QShortcut *cut2 = new QShortcut(this);
    cut2->setKey(QKeySequence("="));

    connect(cut1,&QShortcut::activated,this,&Widget::subVal);
    connect(cut2,&QShortcut::activated,this,&Widget::addVal);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText("当前值为：" + QString::number(value));
}

void Widget::subVal()
{
    int val = ui->horizontalSlider->value();
    if(val <= ui->horizontalSlider->minimum())
    {
        return;
    }
    ui->horizontalSlider->setValue(val-5);
}

void Widget::addVal()
{
    int val = ui->horizontalSlider->value();
    if(val >= ui->horizontalSlider->maximum())
    {
        return;
    }
    ui->horizontalSlider->setValue(val+5);
}
